package online.heycm.rbac.controller.basic;

import online.heycm.platform.common.entity.result.Optional;
import online.heycm.platform.common.entity.result.PageResult;
import online.heycm.platform.common.entity.result.Result;
import online.heycm.rbac.param.basic.ParamCfgAddReq;
import online.heycm.rbac.param.basic.ParamCfgEditReq;
import online.heycm.rbac.param.basic.ParamCfgPageReq;
import online.heycm.rbac.param.basic.ParamCfgRes;
import online.heycm.rbac.service.basic.ParamCfgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 基础服务 - 系统参数配置
 *
 * @author hey
 * @version 1.0
 * @date 2024/1/12 15:34
 */
@RestController
@RequestMapping("/basic/paramCfg")
public class ParamCfgController {

    @Autowired
    private ParamCfgService paramCfgService;

    /**
     * 新增配置
     *
     * @param req
     * @return
     */
    @PostMapping("/add")
    public Result addParamCfg(@RequestBody @Validated ParamCfgAddReq req) {
        Optional optional = paramCfgService.addParamCfg(req);
        return Result.optional(optional);
    }

    /**
     * 更新配置
     *
     * @param req
     * @return
     */
    @PostMapping("/edit")
    public Result editParamCfg(@RequestBody @Validated ParamCfgEditReq req) {
        Optional optional = paramCfgService.editParamCfg(req);
        return Result.optional(optional);
    }

    /**
     * 查询配置详情
     *
     * @param paramId 配置ID
     * @return
     */
    @GetMapping("/{paramId}")
    public Result<ParamCfgRes> queryDetail(@PathVariable Integer paramId) {
        Optional<ParamCfgRes> optional = paramCfgService.queryDetail(paramId);
        return Result.optional(optional);
    }

    /**
     * 配置分页查询
     *
     * @param req
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult<ParamCfgRes>> pageParamCfg(ParamCfgPageReq req) {
        Optional<PageResult<ParamCfgRes>> optional = paramCfgService.pageParamCfg(req);
        return Result.optional(optional);
    }

}
